﻿#include "MainWindow.h"
#include "ui_MainWindow.h"

#include <QPropertyAnimation>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    /// ui->pushButton 给出动画对象
    /// geometry 给出操作属性的对象
    QPropertyAnimation *animation = new QPropertyAnimation(ui->pushButton, "geometry");

    /// 动画时长
    animation->setDuration(3000);

    /// 动画起始位置
    animation->setStartValue(ui->pushButton->geometry());

    /// 动画结束位置
    animation->setEndValue(QRect(200,200,100,50));

    /// 运动曲线
    QEasingCurve curve;

    /// 曲线类型：回弹
    curve.setType(QEasingCurve::OutElastic);

    /// 回弹幅度
    curve.setAmplitude(1.00);

    /// 某些曲线类型会超出终点位置，这里定义效果的大小
    curve.setOvershoot(100);

    /// 曲线周期大小，周期越大，频率越低，只对部分类型有效
    curve.setPeriod(0.1);

    animation->setEasingCurve(curve);

    /// 循环几次,-1代表无限循环
    animation->setLoopCount(-1);

    animation->start();
}

MainWindow::~MainWindow()
{
    delete ui;
}
